package flc.ast.adapter;

import android.widget.ImageView;

import androidx.annotation.NonNull;

import com.blankj.utilcode.util.ConvertUtils;
import com.blankj.utilcode.util.FileUtils;
import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.provider.BaseItemProvider;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;

import flc.ast.R;
import flc.ast.bean.Album;
import flc.ast.bean.AlbumBean;
import flc.ast.bean.Image;
import stark.common.basic.adaptermutil.StkProviderMultiAdapter;

public class AlbumAdapter extends StkProviderMultiAdapter<AlbumBean> {

    public AlbumAdapter() {
        addItemProvider(new AlbumItemProvider());
    }

    private class AlbumItemProvider extends BaseItemProvider<AlbumBean> {
        @Override
        public int getItemViewType() {
            return StkProviderMultiAdapter.TYPE_VIEW;
        }

        @Override
        public int getLayoutId() {
            return R.layout.item_album;
        }

        @Override
        public void convert(@NonNull BaseViewHolder baseViewHolder, AlbumBean bean) {
            baseViewHolder.setText(R.id.tvAlbumItemName, bean.getAlbum().getName());
            long size = 0;
            if (bean.getImages() != null && bean.getImages().size() != 0) {
                baseViewHolder.setText(R.id.tvAlbumItemNum, bean.getImages().size() + getContext().getString(R.string.project_num));
                for (Image image : bean.getImages()) {
                    size += FileUtils.getFileLength(image.path);
                }
                Glide.with(baseViewHolder.itemView).load(bean.getImages().get(0).path).into((ImageView) baseViewHolder.getView(R.id.ivAlbumItemImg));
            } else {
                baseViewHolder.setText(R.id.tvAlbumItemNum, 0 + getContext().getString(R.string.project_num));
                baseViewHolder.setImageResource(R.id.ivAlbumItemImg, R.drawable.akxc);
            }
            baseViewHolder.setText(R.id.tvAlbumItemSize, ConvertUtils.byte2FitMemorySize(size, 1));
        }
    }
}
